import 'plugins/nav';
import 'plugins/serialize-object';
import { post } from 'utils/request';
import { is_obj_lte, getUser } from 'utils';
import E from 'wangeditor';

const user = getUser() || {};

// 初始化导航
$('#nav').nav({ position: 'fixed-top' });

// 定义表单相关变量
const $form = $('#myForm');

// 个人优势富文本编辑器
const advEditor = new E("#advantage");
advEditor.config.height = 200;
advEditor.config.menus = ['list'];
advEditor.config.placeholder = '例如：两年UI设计经验，熟悉IOS和Android的界面设计规范，对产品本色有独特见解，有一定的手绘基础';
advEditor.create();

// 开启表单验证
$form.validator();

// 保存简历
$form.on('submit', function (e) {
  if (e.isDefaultPrevented()) {
    console.log('表单验证不通过');
  } else {
    console.log('表单验证通过');
    e.preventDefault();
    let post_data = $form.serializeObject();
    post_data.advantage = advEditor.txt.html();
    post('resume/resumes', post_data).done(d => {
      alert('简历创建成功');
      location.replace(`resumes.html?uid=${user.id}`);
    });
  }
});
